("Set the scanner compression mode:", "-x<mode> or --compression=<mode>, <mode>='raw', 'none' or 'jpeg' ('jpeg' is default) ('raw' and 'none' are equivalent)", "option", False),
("1. If no dest is provided, the 'file' dest will be automatically invoked.", "", "note", False),
("2. If applications for viewer, editor, or pdf viewer are not provided, reasonable defaults will be used.", "", "note", False),
("3. If --printer is not specified, the CUPS default will be used if available.", "", "note", False),
("4. If an output file is not specified with the 'file' dest, a reasonable default will be used.", "", "note", False),
("5. Some options may not be valid on some scanning devices.", "", "note", False),
("6. The following features are not yet implemented: GUI mode, batch scanning, film/negative scanning, contrast adjustment, brightness adjustment, autocrop, resize to axb, resize to xKB, ", "", "note", False),
utils.USAGE_SPACE,
utils.USAGE_EXAMPLES,
("Quickly (low-res) scan entire page in color to file:", "$ hp-scan -n -r75", "example", False),
("Scan upper left 1in corner and send as email:", '$ hp-scan -n --box=0,0,1,1 -tin -semail --email-from=foo@bar.org --email-to=bar@foo.org --email-note="Test scan" --email-subject="Test scan email"', "example", False),
("Scan entire page in 300dpi grayscale and then edit:", "$ hp-scan -n -seditor -mgray", "example", False),
("Launch the hp-scan GUI:", "$ hp-scan", "example", False),
("Scan into The GIMP:", "$ hp-scan -n --editor=gimp", "example", False),
if output_type and output_type not in ('jpeg', 'png', 'pdf'):
log.error("Invalid output file format. File formats must be 'jpeg', 'png', or 'pdf'.")
sys.exit(1)
#sys.exit(0)
##if scan_mode == 'gray' and output_type and output_type != 'png':
## log.error("Grayscale scans must be saved in PNG file format. To save in other formats, set the 'editor' destination and save the image from the editor in the desired format.")
## sys.exit(1)
if adf and output_type and output_type != 'pdf':
log.error("ADF scans must be saved in PDF file format.")
sys.exit(1)
if 'email' in dest and (not email_from or not email_to):
log.error("Email specified, but email to and/or email from address(es) were not specified.")
log.error("Disabling 'email' destination.")
dest.remove("email")
if page_size:
units = 'mm'
if units == 'in':
if tlx is not None: tlx = tlx * 25.4
if tly is not None: tly = tly * 25.4
if brx is not None: brx = brx * 25.4
if bry is not None: bry = bry * 25.4
elif units == 'cm':
if tlx is not None: tlx = tlx * 10.0
if tly is not None: tly = tly * 10.0
if brx is not None: brx = brx * 10.0
if bry is not None: bry = bry * 10.0
elif units == 'pt':
if tlx is not None: tlx = tlx * 0.3528
if tly is not None: tly = tly * 0.3528
if brx is not None: brx = brx * 0.3528
if bry is not None: bry = bry * 0.3528
elif units == 'px':
log.warn("Units set to pixels. Using resolution of %ddpi for area calculations." % res)
if tlx is not None: tlx = tlx / res * 25.4
if tly is not None: tly = tly / res * 25.4
if brx is not None: brx = brx / res * 25.4
if bry is not None: bry = bry / res * 25.4
if tlx is not None and brx is not None and tlx >= brx:
log.error("Invalid values for tlx (%d) and brx (%d) (tlx>=brx). Using defaults." % (tlx, brx))
tlx = brx = None
if tly is not None and bry is not None and tly >= bry:
log.error("Invalid values for tly (%d) and bry (%d) (tly>=bry). Using defaults." % (tly, bry))
tly = bry = None
# Security: Do *not* create files that other users can muck around with
os.umask (0037)
if not prop.scan_build:
log.error("Scanning disabled in build. Exiting")
sys.exit(1)
if mode == GUI_MODE:
log.error("GUI mode is not implemented yet. Please use -n. Refer to 'hp-scan -h' for help.")
sys.exit(1)
if not prop.gui_build:
log.warn("GUI mode disabled in build. Reverting to interactive mode.")
mode = NON_INTERACTIVE_MODE
elif not os.getenv('DISPLAY'):
log.warn("No display found. Reverting to interactive mode.")
mode = NON_INTERACTIVE_MODE
elif not utils.checkPyQtImport():
log.warn("PyQt init failed. Reverting to interactive mode.")
mode = NON_INTERACTIVE_MODE
if mode == GUI_MODE:
app = None
sendfax = None
from qt import *
# UI Forms
from ui.scanform import ScanForm
# create the main application object
app = QApplication(sys.argv)
if loc is None:
loc = user_cfg.ui.get("loc", "system")
if loc.lower() == 'system':
loc = str(QTextCodec.locale())
log.debug("Using system locale: %s" % loc)
if loc.lower() != 'c':
e = 'utf8'
try:
l, x = loc.split('.')
loc = '.'.join([l, e])
except ValueError:
l = loc
loc = '.'.join([loc, e])
log.debug("Trying to load .qm file for %s locale." % loc)
log.error("A problem has occurred with PDF generation. This is a known bug in ReportLab. Please update your install of ReportLab to version 2.0 or greater.")
sys.exit(1)
c.showPage()
log.info("Saving to file %s" % output)
c.save()
log.info("Viewing PDF file in %s" % pdf_viewer)
os.system("%s %s &" % (pdf_viewer, output))
sys.exit(0)
if resize != 100:
if resize < 1 or resize > 400:
log.error("Resize parameter is incorrect. Resize must be 0% < resize < 400%.")
log.error("Using resize value of 100%.")
else:
new_w = pixels_per_line * resize / 100
new_h = lines * resize / 100
log.info("Resizing from %dx%d to %dx%d..." % (pixels_per_line, lines, new_w, new_h))
im = im.resize((new_w, new_h), Image.ANTIALIAS)
file_saved = False
if 'file' in dest:
log.info("\nOutputting to destination 'file':")
log.info("Saving to file %s" % output)
try:
im.save(output)
except IOError, e:
log.error("Error saving file: %s (I/O)" % e)
try:
os.remove(output)
except OSError:
pass
sys.exit(1)
except ValueError, e:
log.error("Error saving file: %s (PIL)" % e)
try:
os.remove(output)
except OSError:
pass
sys.exit(1)
file_saved = True
dest.remove("file")
temp_saved = False
if ('editor' in dest or 'viewer' in dest or 'email' in dest or 'printer' in dest) \
log.error("A problem has occurred with PDF generation. This is a known bug in ReportLab. Please update your install of ReportLab to version 2.0 or greater.")